﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BondedWareHouse
{
    public partial class F_COM_ProductMasterReference : Form
    {
        public F_COM_ProductMasterReference()
        {
            InitializeComponent();
        }

        private bool _blFind = false;
        private string _Shoh_CD = "";
        private string _Shoh_NM = "";
        private string _Hinmei_NM = "";


        public bool BlFind
        {
            get { return this._blFind; }
            set { _blFind = value; }

        }

        public string Shoh_CD
        {
            get
            {
                return _Shoh_CD;
            }
            set
            {
                _Shoh_CD = value;
            }
        }

        public string Shoh_NM
        {
            get
            {
                return _Shoh_NM;
            }
            set
            {
                _Shoh_NM = value;
            }

        }

        public string Hinmei_NM
        {
            get
            {
                return _Hinmei_NM;
            }
            set 
            {
                _Hinmei_NM = value;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Search_Click(object sender, EventArgs e)
        {
            if (this.txt_Shoh_CD.Text.Trim() == "" && this.txt_Shoh_NM.Text.Trim() == "" && this.txt_Hinmei_NM.Text.Trim() == "")
            {
                MessageBox.Show("请输入查询条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txt_Shoh_CD.Focus();
                return;
            }

            string sqlWhere = "  Where 1=1 ";

            if (this.txt_Shoh_CD.Text.Trim() != "")
            {
                sqlWhere = sqlWhere + "  and Shoh_CD Like '%" + this.txt_Shoh_CD.Text.Trim() + "%'";

            }
            if (this.txt_Shoh_NM.Text.Trim() != "")
            {
                sqlWhere = sqlWhere + "  and Shoh_NM Like '%" + this.txt_Shoh_NM.Text.Trim() + "%'";

            }
            if (this.txt_Hinmei_NM.Text.Trim() != "")
            {
                sqlWhere = sqlWhere + " and Hinmei_NM Like '%" + this.txt_Hinmei_NM.Text.Trim() + "%'";
            }

            string sql = "";
            sql = " select Distinct Shoh_CD,Shoh_NM,Hinmei_NM FROM M_Product_Main " + sqlWhere;

            DataSet ds;
            ds = clsPublic.DB.ReadTable(sql);

            this.dataGridView1.Rows.Clear();

            if ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
            {
               

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow row = ds.Tables[0].Rows[i];
                    object[] values = new object[this.dataGridView1.ColumnCount];
                    values[0] = "选择";
                    values[1] = row["Shoh_CD"].ToString();
                    values[2] = row["Shoh_NM"].ToString();
                    values[3] = row["Hinmei_NM"].ToString();

                    this.dataGridView1.Rows.Add(values);
                }
            }
            else
            {
                MessageBox.Show("数据不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_Shoh_CD.Focus();
            }
        }

        private void panel_Top_Paint(object sender, PaintEventArgs e)
        {

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                this._Shoh_CD = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                this._Shoh_NM = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                this._Hinmei_NM = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                this.DialogResult = DialogResult.OK;
            }
        }

        private void btn_Clear_Click(object sender, EventArgs e)
        {
            this.txt_Shoh_CD.Text = "";
            this.txt_Shoh_NM.Text = "";
            this.txt_Hinmei_NM.Text = "";
            this.dataGridView1.Rows.Clear();
            this.txt_Shoh_CD.Focus();
        }
    }
}
